package com.gxan.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxan.common.R;
import com.gxan.pojo.Human;
import com.gxan.service.HumanService;
import com.gxan.service.impl.HumanServiceImpl;
import com.gxan.utils.DateUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateHuman")
public class UpdateHumanServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取前端传递的参数
        String human_id = request.getParameter("human_id");
        String human_name = request.getParameter("human_name");
        String human_sex = request.getParameter("human_sex");
        String human_birthday = request.getParameter("human_birthday");
        String human_education = request.getParameter("human_education");
        String human_email = request.getParameter("human_email");
        String human_tel = request.getParameter("human_tel");
        String dept_id = request.getParameter("dept_id");
        String human_resume = request.getParameter("human_resume");
        System.out.println(human_sex);
        //2.把数据塞入到Employee对象中传递：方便参数的传递
        Human human = new Human();
        human.setHuman_id(Integer.parseInt(human_id));
        human.setHuman_name(human_name);
        human.setHuman_sex(Integer.parseInt(human_sex));
        human.setHuman_birthday(DateUtils.string2Date(human_birthday));
        human.setHuman_education(human_education);
        human.setHuman_email(human_email);
        human.setHuman_tel(human_tel);
        human.setDept_id(Integer.parseInt(dept_id));
        human.setHuman_resume(human_resume);

        //3.调用service
        HumanService humanService = new HumanServiceImpl();
        R r = humanService.updateHuman(human);
        //4.响应
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSONObject.toJSONString(r));
        response.getWriter().flush();
        response.getWriter().close();
    }
}
